package echecs.tools;

import static echecs.tools.PieceType.BISHOP;
import static echecs.tools.PieceType.KING;
import static echecs.tools.PieceType.KNIGHT;
import static echecs.tools.PieceType.PAWN;
import static echecs.tools.PieceType.QUEEN;
import static echecs.tools.PieceType.ROOK;

import java.util.HashMap;
import java.util.Map;

public enum Piece {

    BLACK_BISHOP('b', false, BISHOP),
    BLACK_KING('k', false, KING),
    BLACK_KNIGHT('n', false, KNIGHT),
    BLACK_PAWN('p', false, PAWN),
    BLACK_QUEEN('q', false, QUEEN),
    BLACK_ROOK('r', false, ROOK),
    WHITE_BISHOP('B', true, BISHOP),
    WHITE_KING('K', true, KING),
    WHITE_KNIGHT('N', true, KNIGHT),
    WHITE_PAWN('P', true, PAWN),
    WHITE_QUEEN('Q', true, QUEEN),
    WHITE_ROOK('R', true, ROOK);
    private static final Map<Character, Piece> FEN_TO_PIECE = new HashMap<Character, Piece>();
    private final char _fenLetter;
    private final boolean _white;
    private final PieceType _type;

    static {
        for (final Piece p : values()) {
            FEN_TO_PIECE.put(Character.valueOf(p.getFENLetter()), p);
        }
    }

    private Piece(final char pLettre, final boolean pBlanc, final PieceType pType) {
        _fenLetter = pLettre;
        _white = pBlanc;
        _type = pType;
    }

    public char getFENLetter() {
        return _fenLetter;
    }

    public PieceType getType() {
        return _type;
    }

    public boolean isWhite() {
        return _white;
    }

    public static Piece valueOf(final char pLettre) {
        return FEN_TO_PIECE.get(Character.valueOf(pLettre));
    }
}
